package com.lxx.train.common.resp;


import com.lxx.train.common.exception.enums.BusinessExceptionEnum;
import lombok.Data;

@Data
public class CommonResp<T> {
    /**
     * 响应业务状态
     */
    private Integer code;

    /**
     * 响应消息
     */
    private String msg;

    /**
     * 响应中的数据
     */
    private T data;

    public CommonResp(T data) {
        this.code = BusinessExceptionEnum.SUCCESS.getCode();
        this.msg = BusinessExceptionEnum.SUCCESS.getMessage();
        this.data = data;
    }

    public CommonResp(Integer status, String msg, T data) {
        this.code = status;
        this.msg = msg;
        this.data = data;
    }

    public static CommonResp ok() {
        return new CommonResp(null);
    }

    public static <T> CommonResp<T> ok(T data) {
        CommonResp<T> commonResp = new CommonResp<>(data);
        return commonResp;
    }

    public static CommonResp error(BusinessExceptionEnum exceptionEnum) {
        return new CommonResp(exceptionEnum.getCode(), exceptionEnum.getMessage(), null);
    }


}
